﻿using StockViz.Data;
using StockViz.Data.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;

namespace StockViz.Controllers.api
{
    public class StockHistoryController : ApiController
    {
        [HttpGet]
        public async Task<IHttpActionResult> Get(string symbol, DateTime startDate, DateTime endDate)
        {
            List<YahooStockQuote> model = new List<YahooStockQuote>();
            if (string.IsNullOrEmpty(symbol))
                return Ok(model);
            //DateTime startDate, endDate;
            //if (!DateTime.TryParse(start.Replace("?", string.Empty), out startDate)) return Ok(model);
            //if (!DateTime.TryParse(end.Replace("?", string.Empty), out endDate)) return Ok(model);
            var client = new YahooClient();
            model = await client.GetHistorical(startDate, endDate, symbol);
            return Ok(model);
        }
    }
}